#!coding=utf-8
from django.core.cache import cache
from django.conf import settings
import time
import datetime
import urllib2
import json
import urllib,urllib2

def sendmessage(telephone,message):
    uri = "http://www.810086.com.cn/jk.aspx"
    zh = getattr(settings,'SMS_ZH')
    mm = getattr(settings,'SMS_MM')
    t = getattr(settings,'SMS_TYPE')
        
    data = dict(zh=zh,mm=mm,hm=telephone,nr=message,sms_type=t)
    
    print data
    
    params = urllib.urlencode(data)
    ret = urllib.urlopen(uri, params)
    content = ret.read()
    
    
    errors = {
        '0':u'提交成功',
        '-1':u'缺少参数',
        '-2':u'有非法字符',
        '-8':u'该账户未开通接口请求功能',
        '-3':u'账户对应的通道余额不足',
        '1':u'服务器异常'
        }
    
    if content.split(':')[0] == '0':
        return {
                    'success':True,
                    'msg':''
                    }
    else:
        return {
                'success':False,
                'msg':errors[content]
                }
        
    
    
    